/* Copyright 2008. All rights reserved. */
package org.bling.process.context;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * <code>Context</code> is an abstract class to be used as a base to form the
 * other contexts of the platform. The intent is to mirror web development's
 * Page, Request, Session and Application context levels that persist attributes
 * at various stages in the lifecycle of the application
 * 
 * @author DISBROB
 * 
 */
public abstract class Context {

	Map<String, Object> attributes = new HashMap<String, Object>();

	public Object getAttribute(String key) {
		return attributes.get(key);
	}

	public void setAttribute(String key, Object value) {
		attributes.put(key, value);
	}
	
	public void setAttributes(Map<String,Object> attr) {
		Iterator<String> keys = attr.keySet().iterator();
		while (keys.hasNext()) {
			String key = keys.next();
			Object value = attr.get(key);
			setAttribute(key,value);
		}
	}
	
	public Map<String,Object> getContext() {
		return attributes;
	}
	
	public Set<String> keySet() {
		return attributes.keySet();
	}
	
	public void reset() {
		 attributes = new HashMap<String, Object>();		
	}
}
